{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from dotenv import load_dotenv\n",
    "\n",
    "load_dotenv()\n",
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI()\n",
    "\n",
    "def chat_completion(prompt, model=\"gpt-4\", temperature=0):\n",
    "    res = client.chat.completions.create(\n",
    "        model=model,\n",
    "        messages=[{\"role\": \"user\", \"content\": prompt}],\n",
    "        temperature=temperature,\n",
    "    )\n",
    "    print(res.choices[0].message.content)\n",
    "\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Context, task and role"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "chat_completion(\"Give me a suggestion for the main course for today's lunch.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt = \"\"\"\n",
    "Context: I do 2 hours of sport a day. I am vegetarian, and I don't like green \n",
    "vegetables. I am conscientious about eating healthily. \n",
    "Task: Give me a suggestion for a main course for today's lunch.\"\"\"\n",
    "chat_completion(prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt = \"\"\"\n",
    "Context: I do 2 hours of sport a day. I am vegetarian and I don't like green \n",
    "vegetables. I am very careful to eat healthily.\n",
    "Task: Give me a suggestion for a main course for today's lunch?\n",
    "Do not perform the requested task! Instead, can you ask me questions about the \n",
    "context so that when I answer, you can perform the requested task more\n",
    "efficiently?\n",
    "\"\"\"\n",
    "chat_completion(prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt = \"\"\"\n",
    "Context: I do 2 hours of sport a day. I am vegetarian, and I don't like green \n",
    "vegetables. I am conscientious about eating healthily.\n",
    "Task: Give me a suggestion for a main course for today's lunch.\n",
    "With this suggestion, I also want a table with two columns where each row \n",
    "contains an ingredient from the main course.\n",
    "The first column in the table is the name of the ingredient.\n",
    "The second column of the table is the number of grams of that ingredient needed \n",
    "for one person. Do not give the recipe for preparing the main course.\n",
    "\"\"\"\n",
    "chat_completion(prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt = \"\"\"\n",
    "Role: You are a nutritionist designing healthy diets for high-performance athletes. You take into account the nutrition needed for a good recovery.\n",
    "Context: I do 2 hours of sport a day. I am vegetarian, and I don't like green vegetables. I am conscientious about eating healthily.\n",
    "Task: Based on your expertise defined in your role. Give me a suggestion for a main course for today's lunch. \n",
    "With this suggestion, I also want a table with two columns where each row in the table contains an ingredient from the main course.\n",
    "The first column in the table is the name of the ingredient.\n",
    "The second column of the table is the number of grams of that ingredient needed for one person. \n",
    "Do not give the recipe for preparing the main course.\n",
    "\"\"\"\n",
    "chat_completion(prompt)\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Thinking Step by Step"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt = \"How much is 369 * 1235?\"\n",
    "chat_completion(prompt)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt = \"How much is 369 * 1235 ? Let's think step by step.\"\n",
    "chat_completion(prompt)\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Few Shot Learning "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt = \"\"\"\n",
    "I go home --> 😊 go 🏠\n",
    "my dog is sad --> my 🐶 is 😞\n",
    "I run fast --> 😊 run ⚡\n",
    "I love my wife --> 😊 ❤️ my wife\n",
    "the girl plays with the ball --> the 👧 🎮 with the 🏀\n",
    "The boy writes a letter to a girl --> \n",
    "\"\"\"\n",
    "chat_completion(prompt)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
